//1.公用样式
//2.公用js
//3.当前页面效果
require('../../assets/css/index.js')
//当前页面样式
require('./home.less')


//2.公用js
let dom = require('../../utils/dom.js');
let http = require('../../utils/http.js');
let https= require('../../utils/https.js');
let local=require('../../utils/local.js')
//3.当前页面效果
// console.log(dom);
//相当于文档加载事件
dom.ready(function () {
  var mySwiper = new Swiper('.swiper', {
    loop: true, // 循环模式选项
    autoplay: true,
    // 如果需要分页器
    pagination: {
      el: '.swiper-pagination',
    },
  })
    dom.click('home');



    // 获取当前用户信息
    let num=dom.getById('.num');
    let day=dom.getById('.day');
    let nums=dom.getById('.nums');
    let Punch=dom.getById('.Punchintoday')
    function getUserInfo(){
      https.get('/api/user/Info',function(res){
        // console.log(res)

        if(res.errno==0){
          local.set('Info',res.data)

          num.textContent=res.data.ranking;
          day.textContent=res.data.clockCount;
          nums.textContent=res.data.badges;
        }
      })    
   
    }
    getUserInfo()

    // 获取打卡信息
    function Getpunchcards(){
      https.get('/api/user/clockInInfo',function(res){
        console.log(res)
        if(res.data.isClockIn==true){
          Punch.textContent='已经打卡'
        }else{
          Punch.textContent='今日打卡'
         
        }
      })
    }
    Getpunchcards()

    // 打卡
        function rank(){
          
          Punch.addEventListener('click',function(){ 

            https.post('/api/user/clockIn',{},function(res){
            console.log(res)
            if(res.errno==0){
              console.log(res) 
              alert('打卡成功')
              getUserInfo();
<<<<<<< HEAD
<<<<<<< HEAD
             
=======
              Getpunchcards();
>>>>>>> wl
=======
              Getpunchcards();
>>>>>>> wl
             
            }else{
              alert(res.message)
             
      
            }
          
          })
          })


    }
    rank()
})